package com.richman.view;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;

import com.richman.controller.AutoBetCentralManager;
import com.richman.controller.DecreaseRatioClient;
import com.richman.controller.SpecialAutoBetCentralManager;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.BetDvalue;
import com.richman.ps38.entity.HGEvent;
import com.richman.utils.Common;
import com.richman.utils.MailManager;
import com.richman.utils.SoundThread;
import com.richman.view.BetLogPane.MyTableModel;

public class BetDvalueLimitPane extends JPanel {
	
	
	
	
	private  Vector<String[]> detailsData = new Vector<String[]>();
	
	
	public SpecialAutoBetCentralManager autobetCtrMng = new SpecialAutoBetCentralManager();
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 189754L;

	long lastbettime = 0;

	public boolean finished = true;

	MyTableModel tableMode = new MyTableModel();
	
	JTable table = null;
	
	Vector<String> emailAlready = new Vector<String>();
	
	

	
	
	Vector<String> betSuccessVec = new Vector<String>();
	
	Vector<String> secondBets = new Vector<String>();
	
	Vector<String> betAlready = new Vector<String>();

	Map<String, Integer> betHistory = new HashMap<String, Integer>(); 
	

	public BetDvalueLimitPane() {
		setLayout(new BorderLayout(0, 0));
		
		
		
	    table = new JTable(tableMode);
	    
	    table.getColumnModel().getColumn(0).setPreferredWidth(5);
	    table.getColumnModel().getColumn(1).setPreferredWidth(100);
	    table.getColumnModel().getColumn(2).setPreferredWidth(150);
	    table.getColumnModel().getColumn(3).setPreferredWidth(120);
	    table.getColumnModel().getColumn(5).setPreferredWidth(40);
	    table.getColumnModel().getColumn(6).setPreferredWidth(200);
	    table.getColumnModel().getColumn(7).setPreferredWidth(200);
	    table.getColumnModel().getColumn(8).setPreferredWidth(170);
	    table.getColumnModel().getColumn(9).setPreferredWidth(50);
	    
	    table.getColumnModel().getColumn(10).setPreferredWidth(40);
	    
	    table.getColumnModel().getColumn(11).setPreferredWidth(100);
	    table.getColumnModel().getColumn(12).setPreferredWidth(100);
	    
	    table.getColumnModel().getColumn(13).setPreferredWidth(170);
	    

	    
	    table.setRowHeight(30);
	    
	    table.setFont(new java.awt.Font("黑体", Font.PLAIN, 15));
	    
	    
		JScrollPane scrollPane = new JScrollPane(table);
		add(scrollPane, BorderLayout.CENTER);
	    
		
	}
	
	
	
	public void updateBetLimitDvalueTable(Vector<BetDvalue> betdvalues){
		
		
		
		try{
			

			double specialMinRatio = DecreaseRatioClient.mainWnd.getSpecialMinRatio();
			double specialDXQMinRatio = DecreaseRatioClient.mainWnd.getSpecialDXQMinRatio();
			int specialBetgold = DecreaseRatioClient.mainWnd.getSpecialBetAmount();
			int specialSecondBetgold = DecreaseRatioClient.mainWnd.getSpecialSecondBetAmount();
			double specialSecondMinRatio = DecreaseRatioClient.mainWnd.getSpecialSecondMinRatio();
			
			int specialDXQBetgold = DecreaseRatioClient.mainWnd.getSpecialDXQBetAmount();
			int specialBetInterval  =DecreaseRatioClient.mainWnd.getspecialBetInterval();
			
			if(detailsData != null) {
				detailsData.clear();
			}
			
			int halfDvalue = DecreaseRatioClient.mainWnd.getdvaluelimit()/2;	//超过一半
			
//			int morethanhalfDvalue = (int) (DaShuiClient.mainWnd.getdvaluelimit()*0.7);	//超级%70
			
			int startIndex = 0;
			
			//只显示达到差值高亮的球赛  开始
			boolean skip = false;
			for(int i = 0; i < betdvalues.size(); i++) {
				BetDvalue  bdvalue = betdvalues.elementAt(i);

				if(!bdvalue.team.equals("")) {
					startIndex = i;
//					if(bdvalue.result.contains("-") && finished == false) {
//						skip = true;
//					}
//					
//					if(!bdvalue.result.contains("-") && finished == true) {
//						skip = true;
//					}
					
				}
				
				if(bdvalue.rqdvalue.contains("/") &&  bdvalue.dxdvalue.contains("/")) {
					if((Integer.parseInt(bdvalue.rqdvalue.split("/")[1]) < DecreaseRatioClient.mainWnd.getdvaluelimit()
							&& Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) < DecreaseRatioClient.mainWnd.getdvaluelimit())
							||skip == true) {
						
						for(int j = i; j  >= startIndex; j--) {
							betdvalues.removeElementAt(j);
						}
						
						i = startIndex -1;
						
					}
					skip = false;
					continue;
					
				}
				
				if(bdvalue.rqdvalue.contains("/") ) {
					if(Integer.parseInt(bdvalue.rqdvalue.split("/")[1]) < DecreaseRatioClient.mainWnd.getdvaluelimit()
							|| skip == true) {
						
						for(int j = i; j  >= startIndex; j--) {
							betdvalues.removeElementAt(j);
						}
						
						i = startIndex -1;
						
					}
					skip = false;
					continue;
					
				}
				
				if(  bdvalue.dxdvalue.contains("/")) {
					if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) < DecreaseRatioClient.mainWnd.getdvaluelimit()
							|| skip == true) {
						
						for(int j = i; j  >= startIndex; j--) {
							betdvalues.removeElementAt(j);
						}
						
						i = startIndex -1;
						
					}
					skip = false;
					continue;
					
				}
				
				
			}
			//只显示达到差值高亮的球赛  结束
			
			
			
			
			
			
			if(DecreaseRatioClient.hasSpecialIllegalBet == true) {
				DecreaseRatioClient.mainWnd.updateMainWndSpecialHasIllegalStatusText(0, "存在非正常投注，已停止投注");;				
				return;				
			}

			
			
			
			
			
			
			
			int index  = 0;
			
			String currentTeam = "";
			String hgps38BaseScore = "";
			String ps38hgBaseScore = "";
			
			int rqplosetimes = 0;
			int rqpwintimes = 0;
			String processscore = "";
			
			int dxplosetimes = 0;
			int dxpwintimes = 0;
			
			Vector<HGEvent> hgEvents = null;//SpecialServer.betCtrMng.getSpecialAccountInplaybet();
			BetDvalue parsingbdvalue = null;
			Vector<HGEvent> processhgevent = new Vector<HGEvent>();
			
			int hgps38BiggestDvalue = 0;
			int ps38hgBiggestDvalue = 0;
			
			
			String firstRQPankou = "";
			String firstDXPankou = "";
		
			//特殊投注处理   开始		
			for(int i = 0; i < betdvalues.size(); i++) {
				
				BetDvalue  bdvalue = betdvalues.elementAt(i);
				String indexstr = "";
				if(!bdvalue.league.equals("")) {
					firstRQPankou = "";
					firstDXPankou = "";
					processhgevent.clear();
					index++;
					indexstr = Integer.toString(index);
					parsingbdvalue = bdvalue;
					processscore = "";
					if(hgEvents != null) {
						for(int jj = 0; jj < hgEvents.size(); jj++ ) {
							if(hgEvents.elementAt(jj).eventId.equals(bdvalue.eventid)) {
								processscore = hgEvents.elementAt(jj).homeTeamScore + ":" + hgEvents.elementAt(jj).awayTeamScore;
								//processhgevent = hgEvents.elementAt(jj);
								processhgevent.add(hgEvents.elementAt(jj));
								
								//break;
							}
						}
						
					}
					
					
					
//					if(bdvalue.team.contains("曼城")) {
//						processscore = "4:5";
//					}
					rqplosetimes = 0;
					rqpwintimes = 0;
					
				}
				
				if(!bdvalue.team.equals("")) {
					currentTeam = bdvalue.team;
				}
				
				if(!bdvalue.rqbetpankou.equals("") && firstRQPankou.equals("")) {
					firstRQPankou = bdvalue.rqbetpankou;
				}
				if(!bdvalue.dxbetpankou.equals("") && firstDXPankou.equals("")) {
					firstDXPankou = bdvalue.dxbetpankou;
				}
				
				
				String rqhgps38timestr = "";
				String rqps38hgtimestr = "";
				if(bdvalue.rqhgps38times!=0) {

					if(hgps38BiggestDvalue < bdvalue.rqhgps38times) {
						hgps38BiggestDvalue = bdvalue.rqhgps38times;
						hgps38BaseScore = bdvalue.betscore;
					}
					
					
					rqhgps38timestr = currentTeam.split("-vs-")[0] + "/" + Integer.toString(bdvalue.rqhgps38times);
					if(!processscore.equals("") && !processscore.equals("0:0")) {
						//计算投注输赢情况
						double betpankou = Double.parseDouble(bdvalue.rqbetpankou);
						double betscore = 0.0;
						if(bdvalue.betscore.equals(":")||bdvalue.betscore.equals("")) {
							betscore = 0.0;
						}else {
							betscore = Double.parseDouble(bdvalue.betscore.split(":")[0]) - Double.parseDouble(bdvalue.betscore.split(":")[1]);
						}
						
						//double pankou1 = betscore - betpankou;
						double currentscore = Double.parseDouble(processscore.split(":")[0]) - Double.parseDouble(processscore.split(":")[1]);
						
						double score = currentscore - betscore;
						
						if(score < betpankou) {
							rqplosetimes += bdvalue.rqhgps38times;
						}else if(score > betpankou) {
							rqpwintimes += bdvalue.rqhgps38times;
						}
						
					}
				}
				
				if(bdvalue.rqps38hgtimes!=0) {
					
					if(ps38hgBiggestDvalue < bdvalue.rqps38hgtimes) {
						ps38hgBiggestDvalue = bdvalue.rqps38hgtimes;
						ps38hgBaseScore = bdvalue.betscore;
					}
					
					rqps38hgtimestr = currentTeam.split("-vs-")[1] + "/" + Integer.toString(bdvalue.rqps38hgtimes);
				
				
					if(!processscore.equals("")&& !processscore.equals("0:0")) {
						//计算投注输赢情况
						double betpankou = 0.0 - Double.parseDouble(bdvalue.rqbetpankou);
						double betscore = 0.0;
						if(bdvalue.betscore.equals(":")||bdvalue.betscore.equals("")) {
							betscore = 0.0;
						}else {
							betscore = Double.parseDouble(bdvalue.betscore.split(":")[1]) - Double.parseDouble(bdvalue.betscore.split(":")[0]);
						}
						
						//double pankou1 = betscore - betpankou;
						double currentscore = Double.parseDouble(processscore.split(":")[1]) - Double.parseDouble(processscore.split(":")[0]);
						
						double score = currentscore - betscore;
						
						if(score < betpankou) {
							rqplosetimes += bdvalue.rqps38hgtimes;
						}else if(score > betpankou) {
							rqpwintimes += bdvalue.rqps38hgtimes;
						}
						
					}
				
				}
				
				String dxhgps38timesrt = "";
				String dxps38hgtimestr = "";
				
				if(bdvalue.dxhgps38times!=0 ) {
					
					dxhgps38timesrt = "大/" + Integer.toString(bdvalue.dxhgps38times);
					
					if(!processscore.equals("")&& !processscore.equals("0:0")) {
						
						int currentballs = Integer.parseInt(processscore.split(":")[0]) + Integer.parseInt(processscore.split(":")[1]);
						
						if(currentballs > Double.parseDouble(bdvalue.dxbetpankou)) {
							
							dxpwintimes+=bdvalue.dxhgps38times;
							
							
						}else if(currentballs < Double.parseDouble(bdvalue.dxbetpankou)) {
							dxplosetimes+=bdvalue.dxhgps38times;
						}
						
					}

					
				}
				
				if(bdvalue.dxps38hgtimes!=0) {
					dxps38hgtimestr = "小/" + Integer.toString(bdvalue.dxps38hgtimes);
					
					if(!processscore.equals("")&& !processscore.equals("0:0")) {
						int currentballs = Integer.parseInt(processscore.split(":")[0]) + Integer.parseInt(processscore.split(":")[1]);
						
						if(currentballs < Double.parseDouble(bdvalue.dxbetpankou)) {
							
							dxpwintimes+=bdvalue.dxps38hgtimes;
							
							
						}else if(currentballs > Double.parseDouble(bdvalue.dxbetpankou)) {
							dxplosetimes+=bdvalue.dxps38hgtimes;
						}
					}
					
					
					
				}
				
				
				
				
				String rqdvaluestr = "";
				
				if(bdvalue.rqdvalue.contains("/")) {
					//高亮显示 开始
					if(Integer.parseInt(bdvalue.rqdvalue.split("/")[1]) >= DecreaseRatioClient.mainWnd.getdvaluelimit()
							) {
						rqdvaluestr = "<html> <font color='red'>" + bdvalue.rqdvalue + "</font>";
						
						
						//赌的方向被进球了才符合条件 begin
						int hgps38d1 = 0;
						if(hgps38BaseScore.equals("")|| hgps38BaseScore.equals(":")) {
							hgps38d1 = 0;
						}else {
							hgps38d1 = Integer.parseInt(hgps38BaseScore.split(":")[0]) - Integer.parseInt(hgps38BaseScore.split(":")[1]);
						}
						
						int ps38hgd1 = 0;
						if(ps38hgBaseScore.equals("")|| ps38hgBaseScore.equals(":")) {
							ps38hgd1 = 0;
						}else {
							ps38hgd1 = Integer.parseInt(ps38hgBaseScore.split(":")[1]) - Integer.parseInt(ps38hgBaseScore.split(":")[0]);
						}
						
						
						
						int d2 = 0;
						
						if(processscore.equals("")||processscore.equals(":")) {
							d2 = 0;
						}else {
							d2 = Integer.parseInt(processscore.split(":")[0]) - Integer.parseInt(processscore.split(":")[1]);
						}
						
						int ps38hgd2 = 0 - d2;
						
						String dvstr = "";
						
						boolean negativeOnescore = false;
						
						if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[0]) && d2 < hgps38d1) {
							dvstr = Integer.toString(d2);
							negativeOnescore = true;
						}
						
						if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[1]) && ps38hgd2 < ps38hgd1) {
							dvstr = Integer.toString(ps38hgd2);
							negativeOnescore = true;
						}
						//赌的方向被进球了才符合条件  end
						
						
						String updownarg = "1";
						if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[0])) {
							updownarg = "1";
						}
						
						if(bdvalue.rqdvalue.contains(parsingbdvalue.team.split("-vs-")[1])) {
							updownarg = "2";
						}
						
						boolean isSecondBet = false;
						

						
					}else {
						rqdvaluestr = bdvalue.rqdvalue;
					}
					//高亮显示结束
					
					
					
					
					hgps38BaseScore = "";
					ps38hgBaseScore = "";
					
					
					
					//让球新邮件开始
					if(Integer.parseInt(bdvalue.rqdvalue.split("/")[1]) >= DecreaseRatioClient.mainWnd.getemailRQDvalue()
							 ) {
						

						
					}
					//让球新邮件结束
					
					
				}
				
				
				
				String dxdvaluestr = "";
				
				if(bdvalue.dxdvalue.contains("/")) {
					//old
					//if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) >= DaShuiClient.mainWnd.getdvaluelimit()) {
					//new
					
					
					
					String updownarg = "";
					
					if(bdvalue.dxdvalue.contains("大")) {
						updownarg = "1";
					}else {
						updownarg = "2";
					}
					
					if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) >= DecreaseRatioClient.mainWnd.getspecialDXQMinBet()) {
						
						dxdvaluestr = "<html> <font color='red'>" + bdvalue.dxdvalue + "</font>";
						//old
//					if(dxplosetimes - dxpwintimes > morethanhalfDvalue && parsingbdvalue!= null && 
//						!emailAlready.contains(parsingbdvalue.eventid+"大小")) {
						//new
						if(!emailAlready.contains(parsingbdvalue.eventid+"大小")) {

						
						//email here
					
//					Vector<String> mails = SpecialServer.getMailList();
//					
//					for(int k = 0, b = 0; k < mails.size()&& b < 50; b++){
//						String mail = mails.elementAt(k);
//					
//					if(true == MailManager.sendMail("240749322@qq.com", "240749322", "zwjiykrxeazgcabh", mail, "打水 大小盘",  parsingbdvalue.league + ":" + parsingbdvalue.team)) {
//						k++;
//					}else {
//						Thread.currentThread().sleep(2000);
//						
//					}
//					
//					
//					
//				}
//					
//					System.out.println("neeed to email 大小:" + parsingbdvalue.team);
//					
//					emailAlready.add(parsingbdvalue.eventid+"大小");
					
				}
						
						
						//赌大小 开始
						//bet here
						int betgold = 0;
						int previousBetgold = 0;
						if(!betHistory.containsKey(parsingbdvalue.eventid + "大小")) {
							betgold = specialDXQBetgold;
						}else {
							if(betHistory.get(parsingbdvalue.eventid + "大小") != null && 
									betHistory.get(parsingbdvalue.eventid + "大小") < specialDXQBetgold) {
								betgold = specialDXQBetgold - betHistory.get(parsingbdvalue.eventid + "大小");
								previousBetgold = betHistory.get(parsingbdvalue.eventid + "大小");
							}
						}
						
						

						//赌大小 结束
						
						
			}else {
						dxdvaluestr = bdvalue.dxdvalue;
					}
					
					int dxqDvalue = 50;
					if(bdvalue.dxdvalue.contains("大")) {
						dxqDvalue = DecreaseRatioClient.mainWnd.getemailDQDvalue();
					}else if(bdvalue.dxdvalue.contains("小")) {
						dxqDvalue = DecreaseRatioClient.mainWnd.getemailXQDvalue();
					}
					
					//大小新邮件开始
					if(Integer.parseInt(bdvalue.dxdvalue.split("/")[1]) >= dxqDvalue
							 ) {
						

						
					}
					//大小新邮件结束
					
					
					hgps38BaseScore = "";
					ps38hgBaseScore = "";
					//processhgevent.clear();
				}
				
				
				//processhgevent.clear();
				
				
				//处理单式大小退水高亮问题
				
				
				if(!indexstr.equals("")) {
					boolean needHighlight = false;
					String danshidaxiaoTmp = bdvalue.danshidaxiao;
					String[] sarry = danshidaxiaoTmp.split("-");
					//int DQBackRatio = BetClient.mainWnd.getDQBackRatio();
					
					//重新生成danshidaxiao
					if(sarry.length>=3) {
						double dxLast = Double.parseDouble(sarry[0]);
						double daRatio = Double.parseDouble(sarry[1]);
						double xiaoRatio = Double.parseDouble(sarry[2]);
						if(daRatio>1.0) {
							daRatio = daRatio-2.0;						
							BigDecimal   b   =   new   BigDecimal(daRatio);  
							daRatio   =   b.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
							
						}
						if(xiaoRatio>1.0) {
							xiaoRatio = xiaoRatio -2.0;
							
										
							BigDecimal   b   =   new   BigDecimal(xiaoRatio);  
							xiaoRatio   =   b.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
							
						}
						bdvalue.danshidaxiao = Double.toString(dxLast) + "、" + Double.toString(daRatio) + "、" +  Double.toString(xiaoRatio);
					}
					
					
					//大球初盘
					double dxFirst = 0.0;
					String dqRatioStr = "";
					for(int jj = 0; jj < betdvalues.size(); jj++) {
						
						if(betdvalues.elementAt(jj).eventid.equals(bdvalue.eventid) &&
								!betdvalues.elementAt(jj).dxbetpankou.equals("") &&
								betdvalues.elementAt(jj).dxhgps38timestr.contains("大")) {							
							dxFirst = Double.parseDouble(betdvalues.elementAt(jj).dxbetpankou);
							dqRatioStr = betdvalues.elementAt(jj).dxhgps38timestr;
							break;
						}
					}
					
					if(dxFirst>0.0) {
						//大小单式终盘
						if(sarry.length>=3) {
							double dxLast = Double.parseDouble(sarry[0]);
							
							if(dxLast>dxFirst) {//如果终盘大于初盘，需要高亮
								needHighlight = true;
							}else if(dxLast==dxFirst) {
								if(!dqRatioStr.equals("")) {
									
									double dqLastRatio = Double.parseDouble(sarry[1]);
									
									double bigRatio = 0.0;
									
									String[] ratioArry = dqRatioStr.split("@");
									
									for(int jj = 0; jj<ratioArry.length;jj++) {
										if(ratioArry[jj].contains("(")) {
											String currentRatioStr = ratioArry[jj].split("\\(")[0].replace(" ", "");
											double currentRatio = Double.parseDouble(currentRatioStr);
											if(currentRatio<0.0) {
												currentRatio = 2.0+currentRatio;
											}
											if(currentRatio>bigRatio) {
												bigRatio = currentRatio;
											}
										}
									}
									
									if(bigRatio - dqLastRatio> 0.0) {
										needHighlight = true;
									}
								}
							}
							
							
						}
					}

				}

				String[] item = {indexstr, bdvalue.league, bdvalue.team, bdvalue.time,
						bdvalue.rqbettype, bdvalue.rqbetpankou, bdvalue.rqhgps38timestr,
						bdvalue.rqps38hgtimestr, rqdvaluestr, bdvalue.dxbettype, 
						bdvalue.dxbetpankou, bdvalue.dxhgps38timestr, bdvalue.dxps38hgtimestr, 
						dxdvaluestr,bdvalue.result};
				
				detailsData.add(item);
				
				
				
			}
			
			
			setOneRowBackgroundColor();
			
			tableMode.updateTable();
			
			
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		

		
		
		
		
	}
	
	
	
	
	
    public void setOneRowBackgroundColor() {

        try {  
        	
            DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
            	
            	
  
                /**
				 * 
				 */
				private static final long serialVersionUID = 123465L;

				public Component getTableCellRendererComponent(JTable table,  
                        Object value, boolean isSelected, boolean hasFocus,  
                        int row, int column) {
					
					int maxPreferredHeight = 18;
					for(int i = 0; i < table.getColumnCount(); i++)
					{
					setText("" + table.getValueAt(row, i));
					//setSize(table.getColumnModel().getColumn(column).getWidth(), 0);
					maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height);
					}

					if(table.getRowHeight(row) != maxPreferredHeight)

{
table.setRowHeight(row, maxPreferredHeight);
					}


                	
                    if (detailsData.elementAt(row)[0].equals("")) {  
                    	setBackground(new Color(246,246,246));  
                        
                    }else{  
                        setBackground(new Color(222,222,243));  
                    	//setBackground(new Color(1,1,1));  
                      
                    }  
                    
                    setHorizontalAlignment(JLabel.CENTER);
  
                    return super.getTableCellRendererComponent(table, value,  
                            isSelected, hasFocus, row, column);  
                }  
            };  
            int columnCount = table.getColumnCount();  
            for (int i = 0; i < columnCount; i++) {  
            	table.getColumn(table.getColumnName(i)).setCellRenderer(tcr);
            }  
        } catch (Exception ex) {  
            ex.printStackTrace();  
        }  
    
    }  
	
	
	
    public class MyTableModel extends AbstractTableModel  
    {  
    	
    	
    	
    	
    	
    	
        /**
		 * 
		 */
		private static final long serialVersionUID = 10086L;
		/* 
         * 这里和刚才一样，定义列名和每个数据的值 
         */  
        String[] columnNames =          
        	{ "序号", "联赛",   "球队", "时间", "投注类型",  "投注盘口", "主",  "客", "手数/金额", "投注类型 ", "投注盘口 ", "大", "小", "手数/金额 ", "赛果"};

  
        /** 
         * 构造方法，初始化二维数组data对应的数据 
         */  
        public MyTableModel()  
        {  

        }  
  
        // 以下为继承自AbstractTableModle的方法，可以自定义  
        /** 
         * 得到列名 
         */  
        @Override  
        public String getColumnName(int column)  
        {  
            return columnNames[column];  
        }  
          
        /** 
         * 重写方法，得到表格列数 
         */  
        @Override  
        public int getColumnCount()  
        {  
            return columnNames.length;  
        }  
  
        /** 
         * 得到表格行数 
         */  
        @Override  
        public int getRowCount()  
        {         
	        if(null == detailsData){
	    		return 0;
	    	}
            return detailsData.size();  
        }  
  
        /** 
         * 得到数据所对应对象 
         */  
        @Override  
        public Object getValueAt(int rowIndex, int columnIndex)  
        {  
            //return data[rowIndex][columnIndex];
        	return detailsData.elementAt(rowIndex)[columnIndex];
        }  
  
        /** 
         * 得到指定列的数据类型 
         */  
        @Override  
        public Class<?> getColumnClass(int columnIndex)  
        {  
        	
        	return String.class;
        	
//        	if(detailsData.size() == 0){
//        		return String.class;
//        	}
//
//            return detailsData.elementAt(0)[columnIndex].getClass();
        	
        }  
  
        /** 
         * 指定设置数据单元是否可编辑.这里设置"姓名","学号"不可编辑 
         */  
        @Override  
        public boolean isCellEditable(int rowIndex, int columnIndex)  
        {  
            return false;
        }  
          
        /** 
         * 如果数据单元为可编辑，则将编辑后的值替换原来的值 
         */  
        @Override  
        public void setValueAt(Object aValue, int rowIndex, int columnIndex)  
        {  
            detailsData.elementAt(rowIndex)[columnIndex] = (String)aValue;  
            /*通知监听器数据单元数据已经改变*/  
            fireTableCellUpdated(rowIndex, columnIndex);  
        }  
        
        public void updateTable(){
        	fireTableDataChanged();
        }
        
  
    }  
	
	
	
	
	
	
}

